const express = require("express")
const router = express()
let multer = require("multer")


const { upload_rules } = require("../rule/upload.js")

const { uploadFile } = require("../views/upload.js")

// 配置文件
let storage = multer.diskStorage({
    destination:'../public/uploads/',
    filename:function(req,file,cb){
        
        // 获取文件扩展名
        let fileFormat = file.originalname.split(".")
        let extname = fileFormat[fileFormat.length-1]
        cb(null,Date.now().getTime() + "."+extname)
    }
})
let upload = multer({storage})

router.post("/single/uploadFile",upload.single('avatarFile'), uploadFile)

module.exports = router